function [error , threshold, parity] = weak_classifier(mu1 , sigma1 , mu2 , sigma2, feature, weight)

% mu1 ----> mu_negative  

example_size = length(feature);

if sigma1 == sigma2
    threshold_1 = (mu1 + mu2)/2;
    threshold_2 = threshold_1;

	else 

    a1 = sigma1 * sigma2 * log(abs(sigma1));
    a2 = sigma1 * sigma2 * log(abs(sigma2));

    A = sigma2 - sigma1;
    B = sigma2*mu1 - sigma1*mu2;
    C = sigma2*(mu1^2) - sigma1*(mu2^2) + a1 - a2;

    threshold_1 = (B + sqrt(B^2 - A*C))/A;
    threshold_2 = (B - sqrt(B^2 - A*C))/A;

end

%%  if feature > threshold return 1,  car region
%%  if feature < threshold return 0,  non-car region

% feature = feature.*weight';

negative = feature(1:500);
positive = feature(501:1000);

if mu1 < mu2    
	threshold = min(threshold_1 , threshold_2);
	parity = 1;
    
  	error =  (length(find(negative > threshold)) + length(find(positive < threshold)) )/1000;
   
else 	
	threshold = max(threshold_1 , threshold_2);
	parity = -1;
    error =  (length(find(negative < threshold)) + length(find(positive > threshold)) )/1000;
end





	
